package org.fund.base_service.factory;

import org.fund.base_service.domain.TransactionRecord;
import org.fund.base_service.domain.vo.TransactionRecordVO;
import org.fund.base_service.service.PositionService;
import org.fund.common.constant.OperatorType;
import org.fund.common.core.domain.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;

/**
 * @Author Moro
 * @Date 2022/3/19 13:44
 * @title OperatorFactory
 */
@Component
public class OperatorFactory {
    @Autowired
    private PositionService positionService;

    public BaseResult doOperator(TransactionRecordVO record){
        int type = record.getOperatorType();
        if (type == OperatorType.PURCHASE.getCode()){
            try {
                positionService.purchase(record);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }else if (type == OperatorType.SALE.getCode()){
            positionService.sale(record);
        }
        return  BaseResult.success(Boolean.TRUE);
    }

}
